#!/bin/sh
#
# Check tracing of looping threads.
#
# Copyright (c) 2009-2020 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later

. "${srcdir=.}/init.sh"
. "${srcdir=.}/PTRACE_SEIZE.sh"

run_prog ../orphaned_process_group > /dev/null

run_prog_skip_if_failed date +%s > /dev/null
s0="$(date +%s)"

check_prog nproc
inc="$(nproc)"
[ "$inc" -ge 1 ] || inc=1

timeout_2="$(($TIMEOUT_DURATION/2))"
timeout_16="$(($TIMEOUT_DURATION/16))"
nproc=1

run_prog "../$NAME" "$timeout_16" "$nproc"

while :; do
	run_strace --follow-forks -qq -enone -esignal=none "../$NAME" "$timeout_2" "$nproc"

	s1="$(date +%s)"
	[ "$(($s1-$s0))" -lt "$timeout_16" ] ||
		break

	nproc="$(($nproc+$inc))"
done

warn_ "$ME_: nproc=$nproc elapsed=$(($s1-$s0))"
